#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys
import logging
import bottle

from bottle import Bottle,run,SimpleTemplate
from beaker.middleware import SessionMiddleware

# Define some config values here for later export
BASEURL = '/sa'
LOGFILE = './saplatform.log'


# Add some default value to SimpleTemplate for refers in views
SimpleTemplate.defaults['BASEURL'] = BASEURL

base = Bottle()

from bottle import static_file
main = Bottle()
base.mount(BASEURL, main)
@main.route('/static/<filename:path>')
def sendStatic(filename):
    return static_file(filename, root="./static")

from serverapp import serverapp
main.mount('/server', serverapp)
serverapp.appurl = BASEURL + '/server'

logging.basicConfig(filename = LOGFILE,
                    level = logging.DEBUG,
                    format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s")

bottle.debug(True)

# Add session middleware
session_opts = {'session.type' : 'file',
                'session.cookie_expires' : 28800,
                'session.data_dir' : './data',
                'session.auto': True,
                }
base = SessionMiddleware(base, session_opts)

bottle.run(base,
           server = 'paste',
           host = "127.0.0.1",
           port = 20010,
           reloader = True)
